%%%-------------------------------------------------------------------
%%% File    : kfm_triple_flattener.erl
%%% Author  :  <vjache>
%%% Description : 
%%%
%%% Created : 22 Apr 2009 by  <vjache>
%%%-------------------------------------------------------------------
-module(kfm_triple_flattener).

-include("../include/valg.hrl").

%% API
-export([new/3]).

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: 
%% Description:
%%--------------------------------------------------------------------
new(InRecName,OutRecName,PredList) ->
	#kfm{fold_fun=
			 fun({RecName,_S,P,_O}=E,Dict) when RecName==InRecName ->
					 dict:append(P, E, Dict)
			 end,
		 acc0=dict:new(),
		 record_fun=
			 fun(S,Dict) ->
					 L=[case dict:find(P, Dict) of
							{ok,TList}->
								[Val||{_InRecName,_S,_P,Val}<-TList];
							error ->
								[]
						end||P<-PredList],
					 list_to_tuple([OutRecName,S|L])
			 end
		}.

%%====================================================================
%% Internal functions
%%====================================================================
